package com.sakura.util;/**
 * Created by apple on 2019/3/25.
 */

/**
 * @author jixd
 * @Description TODO
 * @Date 2019/3/25 4:17 PM
 * @Version 1.0
 **/
public class StringUtils {
    /**
     * 将下划线转为大驼峰
     * @param str   目标字符串
     * @return  变为大驼峰的字符串
     */
    public static String underlineToBigCamel(String str){
        return underlineToSmallCamel(str.toUpperCase().substring(0,1)+str.substring(1));
    }

    /**
     * 将下划线转为小驼峰
     * @param str   目标字符串
     * @return  变为小驼峰的字符串
     */
    public static String underlineToSmallCamel(String str){
        if (str==null||"".equals(str.trim())){
            return "";
        }
        int len=str.length();
        StringBuilder sb=new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c=str.charAt(i);
            if (c=='_'){
                if (++i<len){
                    sb.append(Character.toUpperCase(str.charAt(i)));
                }
            }else{
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
